﻿//=====================================================================================================
// LocalizationLibrary
// The Localization Library is a collection of reusable software components that provide 
// support for localization. This library enables you to localize WPF, Silverlight and WP7 applications.
// (http://localizationlibrary.codeplex.com)
//=====================================================================================================
// Author: Nicola Gallo (Website: www.nicola.gallo.name, Email: nicolagmt@hotmail.it) 
//=====================================================================================================

namespace LocalizationLibrary.Tests.Core.Reflection
{
    //.NET References
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using System.Runtime.Serialization;
    using System.Text;

    //LocalizationLibrary References
    using LocalizationLibrary.Reflection;

    //Microsoft References
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class TypeRefTest
    {

        [TestMethod]
        public void GetHashCode_Should_Be_Always_The_Same()
        {
            Type type = typeof(String);
            TypeRef instance = new TypeRef(type);
            Assert.AreEqual(instance.GetHashCode(), type.FullName.GetHashCode());
        }

        [TestMethod]
        public void GetHashCode_Should_Be_Not_Equal()
        {
            TypeRef instance = new TypeRef(typeof(String));
            TypeRef instance2 = new TypeRef(typeof(DataContractAttribute));
            Assert.AreNotEqual(instance.GetHashCode(), instance2.GetHashCode());
        }

        [TestMethod]
        public void Verify_If_Two_Instance_Are_Equals()
        {
            Type type = typeof(String);
            TypeRef instance = new TypeRef(type);

            Assert.AreEqual(instance.Equals(null), false);
            Assert.AreEqual(instance.Equals(instance), true);

            TypeRef instance2 = new TypeRef(type);

            Assert.AreEqual(instance.Equals(instance2), true);

            instance2 = new TypeRef(typeof(DataContractAttribute));

            Assert.AreEqual(instance.Equals(instance2), false);
        }

        [ExpectedException(typeof(ArgumentNullException))]
        [TestMethod]
        public void New_Instance_Thrown_ArgumentException_If_Type_Is_Null()
        {
            TypeRef instance = new TypeRef(null);
        }
    }
}